﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Innova.Microfinanzas.BusinessEntities;

namespace MyCommerce.Business.GeneralParameters
{
    public class CommonClassifierTypeManager
    {
        private MyCommerceEntities vContext;

        public CommonClassifierTypeManager()
        {
            if (vContext == null)
            {
                vContext = new MyCommerceEntities();
                vContext.ContextOptions.LazyLoadingEnabled = false;
            }
        }

        public CommonClassifierTypeManager(bool lazyLoad)
        {
            if (vContext == null)
            {
                vContext = new MyCommerceEntities();
                vContext.ContextOptions.LazyLoadingEnabled = lazyLoad;
            }
        }

        public List<ClassifierType> GetListClassifierTypeByIsSystem(Boolean pIsSystem)
        {
            List<ClassifierType> colClassifierType = new List<ClassifierType>();
            var classifierResult = from clt in vContext.ClassifierType
                                   .Include("Classifier")
                                   where clt.IsSystem == pIsSystem
                                   select clt;

            if (classifierResult != null)
            {
                colClassifierType = new List<ClassifierType>(classifierResult.AsEnumerable<ClassifierType>());
            }

            return colClassifierType;
        }

        public List<ClassifierType> GetListClassifierTypeIsActive(Boolean pIsActive)
        {
            List<ClassifierType> colClassifierType = new List<ClassifierType>();
            var classifierResult = from clt in vContext.ClassifierType
                                   where clt.IsActive == pIsActive
                                   select clt;

            if (classifierResult != null)
            {
                colClassifierType = new List<ClassifierType>(classifierResult.AsEnumerable<ClassifierType>());
            }

            return colClassifierType;
        }

        public ClassifierType GetClassifierByID(long IdClassifierType)
        {
            ClassifierType objClassifierType = new ClassifierType();
            var classifierTypeResult = (from clt in vContext.ClassifierType
                                   where clt.IdClassifierType == IdClassifierType
                                   select clt).First();
            objClassifierType = (ClassifierType)classifierTypeResult;
            return objClassifierType;
        }
    }
}
